﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class FixedJoystickHandler : MonoBehaviour,IDragHandler,IEndDragHandler,IBeginDragHandler {

    //处理摇杆事件
    [System.Serializable]
    public class VirtualJoystickEvent : UnityEvent<Vector3> { }
    //设置虚拟操作摇杆栏位
    
    public Transform content;
    public UnityEvent beginControl;
    public VirtualJoystickEvent controlling;
    public UnityEvent endControl;

    //在这里注入外部的事件
    public void OnBeginDrag(PointerEventData eventData)
    {
        this.beginControl.Invoke();
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (this.content)
        {
            this.controlling.Invoke(this.content.localPosition.normalized);
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        this.endControl.Invoke();
    }

    
}
